package top.tangyh.lamp.care.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import top.tangyh.basic.base.mapper.SuperMapper;
import top.tangyh.lamp.care.entity.BHl7RkDetail;
import org.springframework.stereotype.Repository;
import top.tangyh.lamp.care.vo.result.BHl7MoveDetailResultVO;
import top.tangyh.lamp.care.vo.result.Hl7RkDetailOutVO;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 入科明细表
 * </p>
 *
 * @author zqb
 * @date 2024-07-15 11:16:18
 * @create [2024-07-15 11:16:18] [zqb] [代码生成器生成]
 */
@Repository
public interface BHl7RkDetailMapper extends SuperMapper<BHl7RkDetail> {



    List<BHl7RkDetail>  selectHistoryPatients(LocalDateTime startTime,LocalDateTime endTime,String nameOrHospitalNum);
    List<BHl7RkDetail> selectRkListOfTopNewTime(List<String> hospitalNumbers);

    default BHl7RkDetail selectOneByHospitalNumber(String hospitalNumber) {
        LambdaQueryWrapper<BHl7RkDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BHl7RkDetail::getHospitalNumber, hospitalNumber)
                .orderByDesc(BHl7RkDetail::getRkTime)
                .last("limit 1");
        return this.selectOne(queryWrapper);
    }

    default List<BHl7RkDetail> selectNextRkByPatientIdentAndRkTime(String patientIdent, LocalDateTime rkTime, Long id){
        LambdaQueryWrapper<BHl7RkDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BHl7RkDetail::getPatientIdent,patientIdent).ge(BHl7RkDetail::getRkTime,rkTime)
                .ne(BHl7RkDetail::getId,id).orderByAsc(BHl7RkDetail::getRkTime).last(" limit 1");
        return selectList(queryWrapper);

    }

    List<Hl7RkDetailOutVO> selectRkListOfHistoryPatientNew(String patientIdent, String hospitalNumber);

}


